/*
 * Copyright (c) 2000-2018, 达梦数据库有限公司.
 * All rights reserved.
 */
package dm

import (
	"container/list"
	"io"
)

type Dm_build_900 struct {
	dm_build_901 *list.List
	dm_build_902 *dm_build_954
	dm_build_903 int
}

func Dm_build_904() *Dm_build_900 {
	return &Dm_build_900{
		dm_build_901: list.New(),
		dm_build_903: 0,
	}
}

func (dm_build_906 *Dm_build_900) Dm_build_905() int {
	return dm_build_906.dm_build_903
}

func (dm_build_908 *Dm_build_900) Dm_build_907(dm_build_909 *Dm_build_978, dm_build_910 int) int {
	var dm_build_911 = 0
	var dm_build_912 = 0
	for dm_build_911 < dm_build_910 && dm_build_908.dm_build_902 != nil {
		dm_build_912 = dm_build_908.dm_build_902.dm_build_962(dm_build_909, dm_build_910-dm_build_911)
		if dm_build_908.dm_build_902.dm_build_957 == 0 {
			dm_build_908.dm_build_944()
		}
		dm_build_911 += dm_build_912
		dm_build_908.dm_build_903 -= dm_build_912
	}
	return dm_build_911
}

func (dm_build_914 *Dm_build_900) Dm_build_913(dm_build_915 []byte, dm_build_916 int, dm_build_917 int) int {
	var dm_build_918 = 0
	var dm_build_919 = 0
	for dm_build_918 < dm_build_917 && dm_build_914.dm_build_902 != nil {
		dm_build_919 = dm_build_914.dm_build_902.dm_build_966(dm_build_915, dm_build_916, dm_build_917-dm_build_918)
		if dm_build_914.dm_build_902.dm_build_957 == 0 {
			dm_build_914.dm_build_944()
		}
		dm_build_918 += dm_build_919
		dm_build_914.dm_build_903 -= dm_build_919
		dm_build_916 += dm_build_919
	}
	return dm_build_918
}

func (dm_build_921 *Dm_build_900) Dm_build_920(dm_build_922 io.Writer, dm_build_923 int) int {
	var dm_build_924 = 0
	var dm_build_925 = 0
	for dm_build_924 < dm_build_923 && dm_build_921.dm_build_902 != nil {
		dm_build_925 = dm_build_921.dm_build_902.dm_build_971(dm_build_922, dm_build_923-dm_build_924)
		if dm_build_921.dm_build_902.dm_build_957 == 0 {
			dm_build_921.dm_build_944()
		}
		dm_build_924 += dm_build_925
		dm_build_921.dm_build_903 -= dm_build_925
	}
	return dm_build_924
}

func (dm_build_927 *Dm_build_900) Dm_build_926(dm_build_928 []byte, dm_build_929 int, dm_build_930 int) {
	if dm_build_930 == 0 {
		return
	}
	var dm_build_931 = dm_build_958(dm_build_928, dm_build_929, dm_build_930)
	if dm_build_927.dm_build_902 == nil {
		dm_build_927.dm_build_902 = dm_build_931
	} else {
		dm_build_927.dm_build_901.PushBack(dm_build_931)
	}
	dm_build_927.dm_build_903 += dm_build_930
}

func (dm_build_933 *Dm_build_900) dm_build_932(dm_build_934 int) byte {
	var dm_build_935 = dm_build_934
	var dm_build_936 = dm_build_933.dm_build_902
	for dm_build_935 > 0 && dm_build_936 != nil {
		if dm_build_936.dm_build_957 == 0 {
			continue
		}
		if dm_build_935 > dm_build_936.dm_build_957-1 {
			dm_build_935 -= dm_build_936.dm_build_957
			dm_build_936 = dm_build_933.dm_build_901.Front().Value.(*dm_build_954)
		} else {
			break
		}
	}
	return dm_build_936.dm_build_975(dm_build_935)
}
func (dm_build_938 *Dm_build_900) Dm_build_937(dm_build_939 *Dm_build_900) {
	if dm_build_939.dm_build_903 == 0 {
		return
	}
	var dm_build_940 = dm_build_939.dm_build_902
	for dm_build_940 != nil {
		dm_build_938.dm_build_941(dm_build_940)
		dm_build_939.dm_build_944()
		dm_build_940 = dm_build_939.dm_build_902
	}
	dm_build_939.dm_build_903 = 0
}
func (dm_build_942 *Dm_build_900) dm_build_941(dm_build_943 *dm_build_954) {
	if dm_build_943.dm_build_957 == 0 {
		return
	}
	if dm_build_942.dm_build_902 == nil {
		dm_build_942.dm_build_902 = dm_build_943
	} else {
		dm_build_942.dm_build_901.PushBack(dm_build_943)
	}
	dm_build_942.dm_build_903 += dm_build_943.dm_build_957
}

func (dm_build_945 *Dm_build_900) dm_build_944() {
	var dm_build_946 = dm_build_945.dm_build_901.Front()
	if dm_build_946 == nil {
		dm_build_945.dm_build_902 = nil
	} else {
		dm_build_945.dm_build_902 = dm_build_946.Value.(*dm_build_954)
		dm_build_945.dm_build_901.Remove(dm_build_946)
	}
}

func (dm_build_948 *Dm_build_900) Dm_build_947() []byte {
	var dm_build_949 = make([]byte, dm_build_948.dm_build_903)
	var dm_build_950 = dm_build_948.dm_build_902
	var dm_build_951 = 0
	var dm_build_952 = len(dm_build_949)
	var dm_build_953 = 0
	for dm_build_950 != nil {
		if dm_build_950.dm_build_957 > 0 {
			if dm_build_952 > dm_build_950.dm_build_957 {
				dm_build_953 = dm_build_950.dm_build_957
			} else {
				dm_build_953 = dm_build_952
			}
			copy(dm_build_949[dm_build_951:dm_build_951+dm_build_953], dm_build_950.dm_build_955[dm_build_950.dm_build_956:dm_build_950.dm_build_956+dm_build_953])
			dm_build_951 += dm_build_953
			dm_build_952 -= dm_build_953
		}
		if dm_build_948.dm_build_901.Front() == nil {
			dm_build_950 = nil
		} else {
			dm_build_950 = dm_build_948.dm_build_901.Front().Value.(*dm_build_954)
		}
	}
	return dm_build_949
}

type dm_build_954 struct {
	dm_build_955 []byte
	dm_build_956 int
	dm_build_957 int
}

func dm_build_958(dm_build_959 []byte, dm_build_960 int, dm_build_961 int) *dm_build_954 {
	return &dm_build_954{
		dm_build_959,
		dm_build_960,
		dm_build_961,
	}
}

func (dm_build_963 *dm_build_954) dm_build_962(dm_build_964 *Dm_build_978, dm_build_965 int) int {
	if dm_build_963.dm_build_957 <= dm_build_965 {
		dm_build_965 = dm_build_963.dm_build_957
	}
	dm_build_964.Dm_build_1057(dm_build_963.dm_build_955[dm_build_963.dm_build_956 : dm_build_963.dm_build_956+dm_build_965])
	dm_build_963.dm_build_956 += dm_build_965
	dm_build_963.dm_build_957 -= dm_build_965
	return dm_build_965
}

func (dm_build_967 *dm_build_954) dm_build_966(dm_build_968 []byte, dm_build_969 int, dm_build_970 int) int {
	if dm_build_967.dm_build_957 <= dm_build_970 {
		dm_build_970 = dm_build_967.dm_build_957
	}
	copy(dm_build_968[dm_build_969:dm_build_969+dm_build_970], dm_build_967.dm_build_955[dm_build_967.dm_build_956:dm_build_967.dm_build_956+dm_build_970])
	dm_build_967.dm_build_956 += dm_build_970
	dm_build_967.dm_build_957 -= dm_build_970
	return dm_build_970
}

func (dm_build_972 *dm_build_954) dm_build_971(dm_build_973 io.Writer, dm_build_974 int) int {
	if dm_build_972.dm_build_957 <= dm_build_974 {
		dm_build_974 = dm_build_972.dm_build_957
	}
	dm_build_973.Write(dm_build_972.dm_build_955[dm_build_972.dm_build_956 : dm_build_972.dm_build_956+dm_build_974])
	dm_build_972.dm_build_956 += dm_build_974
	dm_build_972.dm_build_957 -= dm_build_974
	return dm_build_974
}
func (dm_build_976 *dm_build_954) dm_build_975(dm_build_977 int) byte {
	return dm_build_976.dm_build_955[dm_build_976.dm_build_956+dm_build_977]
}
